<template>
    <div class="loginForm">
        <el-form :rules="rules"  :model="userData" ref="loginForm">
            <h3>系统登录</h3>
            <el-form-item prop="username">
                <el-input type="test" placeholder="请输入用户名" v-model="userData.username"></el-input>
            </el-form-item>
            <el-form-item prop="password">
                <el-input type="password" placeholder="请输入密码" v-model="userData.password"></el-input>
            </el-form-item>
            <el-form-item>
                <el-checkbox v-model="remember" >记住密码</el-checkbox>
            </el-form-item>
            <el-button class="loginBtn" type="primary" size="small" @click="submitLogin">登录</el-button>

        </el-form>
    </div>
</template>

<script>
    export default {
        name: "Login",
        data(){
            return{
                userData:{
                    username:'admin',
                    password:'123'
                },

                remember:true,

                rules:{
                   username:[{require:true,message:'请正确填写用户名',trigger:'blur'}],
                   password:[{require:true,message:'请正确填写用户名',trigger:'blur'}],
                }
            }
        },

        methods:{
            submitLogin(){
                this.$refs['loginForm'].validate((valid) => {
                    if (valid) {
                        //向后端发送请求
                        this.$postKeyValueRequest('/doLogin',this.userData).then(resp=>{
                            if (resp){
                                window.sessionStorage.setItem('loginer',JSON.stringify(resp.data));
                                this.$router.replace('/Home');
                            }
                        })
                    } else {
                        this.$message.warning ("请正确填写信息");
                        return false;
                    }
                });
            },


        },


    }
</script>

<style scoped>
    .loginForm{
        width: 400px;
        padding: 20px;
        margin: 180px auto;
        border-radius: 15px;
        box-shadow:0 0 25px #898989;


    }

    .loginForm h3{
        text-align: center;
        color:black;
    }
    .loginBtn{
        width: 100%;
    }



</style>